home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / doom / ldhe-src.0 / ldhe-src / dehacked / source / snd2au.cc < prev    next >
Text File  |  1995-03-22  |  3KB  |  72 lines

  1. /************************************************************************/
  2. /*      Copyright 1989 by Rich Gopstein and Harris Corporation          */
  3. /*                                                                      */
  4. /*      Permission to use, copy, modify, and distribute this software   */
  5. /*      and its documentation for any purpose and without fee is        */
  6. /*      hereby granted, provided that the above copyright notice        */
  7. /*      appears in all copies and that both that copyright notice and   */
  8. /*      this permission notice appear in supporting documentation, and  */
  9. /*      that the name of Rich Gopstein and Harris Corporation not be    */
  10. /*      used in advertising or publicity pertaining to distribution     */
  11. /*      of the software without specific, written prior permission.     */
  12. /*      Rich Gopstein and Harris Corporation make no representations    */
  13. /*      about the suitability of this software for any purpose.  It     */
  14. /*      provided "as is" without express or implied warranty.           */
  15. /************************************************************************/
  16.  
  17. /************************************************************************/
  18. /* sound2sun.c - Convert sampled audio files into uLAW format for the   */
  19. /*               Sparcstation 1.                                        */
  20. /*               Send comments to ..!rutgers!soleil!gopstein            */
  21. /************************************************************************/
  22. /*                                    */
  23. /*  Modified November 27, 1989 to convert to 8000 samples/sec           */
  24. /*   (contrary to man page)                                             */
  25. /*                                    */
  26. /*  Fixed Bug with converting slow sample speeds            */
  27. /*                                    */
  28. /************************************************************************/
  29. /*                                    */
  30. /*  Modified 11/1991                            */
  31. /*  By nevs@opal.cs.tu-berlin.de                    */
  32. /*   (contrary to man page)                                             */
  33. /*                                    */
  34. /*                                    */
  35. /************************************************************************/
  36.  
  37. /* convert two's complement ch into uLAW format */
  38.  
  39. unsigned int sample_cvt(int ch)
  40. {
  41.  
  42.   int mask;
  43.  
  44.   if (ch < 0) {
  45.     ch = -ch;
  46.     mask = 0x7f;
  47.   } else {
  48.     mask = 0xff;
  49.   }
  50.  
  51.   if (ch < 32) {
  52.     ch = 0xF0 | 15 - (ch / 2);
  53.   } else if (ch < 96) {
  54.     ch = 0xE0 | 15 - (ch - 32) / 4;
  55.   } else if (ch < 224) {
  56.     ch = 0xD0 | 15 - (ch - 96) / 8;
  57.   } else if (ch < 480) {
  58.     ch = 0xC0 | 15 - (ch - 224) / 16;
  59.   } else if (ch < 992) {
  60.     ch = 0xB0 | 15 - (ch - 480) / 32;
  61.   } else if (ch < 2016) {
  62.     ch = 0xA0 | 15 - (ch - 992) / 64;
  63.   } else if (ch < 4064) {
  64.     ch = 0x90 | 15 - (ch - 2016) / 128;
  65.   } else if (ch < 8160) {
  66.     ch = 0x80 | 15 - (ch - 4064) /  256;
  67.   } else {
  68.     ch = 0x80;
  69.   }
  70. return (mask & ch);
  71. }
  72.